<?php

class sfWidgetFormUploadify extends sfWidgetFormInput
{
  protected function configure($options = array(), $attributes = array())
  {
    $this->setAttribute('disabled', 'disabled');
    $this->addOption('multi');
    $this->addOption('files');
    $this->addOption('uploadDirectory');
    $this->addOption('field');    

    parent::configure($options, $attributes);
  }
  
  public function render($name, $value = null, $attributes = array(), $errors = array())
  {    
    $field = $this->getOption('field');
    $field['value'] = $this->getOption('files');
    
    $id = $this->generateId($name);
    
    $partial = get_partial("form/widget_uploadify", 
                 array(
                    'id'    => $id, 
                    'folder'=> $this->getOption('uploadDirectory'),
                    'multi' => $this->getOption('multi') ? 'true' : 'false',
                    'field' => $field
                  ));
    
    $wraper= "<div id='$id-wrapper'>%s</div>";
    
    $return = sprintf($wraper, parent::render($name, $value, $attributes, $errors) . $partial);
    
    return $return;
  }
  
  /**
   * Gets the stylesheet paths associated with the widget.
   *
   * @return array An array of stylesheet paths
   */
  public function getStylesheets()
  {
    return array('../external/uploadify/uploadify.css' => 'all');
  }

  /**
   * Gets the JavaScript paths associated with the widget.
   *
   * @return array An array of JavaScript paths
   */
  public function getJavascripts()
  {
    return array('../external/uploadify/swfobject.js', '../external/uploadify/jquery.uploadify.v2.1.4.min.js');
  }
}
